package woa.sort;

import java.util.Arrays;

/**
 * 冒泡排序
 *
 * @author wangpeng
 * @date 2022/1/10
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = new int[]{4,3,5,6,71};

        for (int i = 1; i < arr.length; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    flag = true;
                }
            }
            if (!flag) {
                break;
            }
        }

        System.out.println(Arrays.toString(arr));
    }
}
